package edu.sju.ssm;

import java.util.List;

import org.apache.ibatis.session.SqlSessionFactory;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;

import edu.sju.ssm.config.DataAccessConfig;
import edu.sju.ssm.config.MyBatisConfig;
import edu.sju.ssm.entity.Publisher;
import edu.sju.ssm.mapper.PublisherMapper;

public class MyBatisTest {

	public static void main(String[] args) {
		AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(MyBatisConfig.class, DataAccessConfig.class);
		
		SqlSessionFactory sessionFactory = ctx.getBean(SqlSessionFactory.class);
		System.out.println(sessionFactory);
		
		PublisherMapper mapper = ctx.getBean(PublisherMapper.class);
		
		int count = mapper.selectPublisherCount();
		System.out.println("出版社数量：" + count);
		
		List<Publisher> publishers = mapper.selectAllPublishers();
		
		for (Publisher publisher : publishers) {
			System.out.println(publisher);
		}
		
		ctx.close();
	}

}
